#!/bin/sh

ulimit -s 1024
export LD_LIBRARY_PATH=/home/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/tmp/sd/yi-hack-v5/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/app/locallib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/hisiko/hisilib:$LD_LIBRARY_PATH
export PATH=/home/app:$PATH
export PATH=/home/app/localbin:$PATH
export PATH=/home/base/tools:$PATH
export PATH=/tmp/sd/yi-hack-v5/bin:$PATH
export PATH=/tmp/sd/yi-hack-v5/sbin:$PATH

CONF_FILE="etc/system.conf"
if [ -d "/tmp/sd/yi-hack-v5" ]; then
        YI_HACK_V5_PREFIX="/tmp/sd/yi-hack-v5"
elif [ -d "/home/yi-hack-v5" ]; then
        YI_HACK_V5_PREFIX="/home/yi-hack-v5"
fi

get_config()
{
	key=$1
	grep $1 $YI_HACK_V5_PREFIX/$CONF_FILE | cut -d "=" -f2
}

if [[ $(get_config DISABLE_CLOUD) == "yes" ]] ; then
        cd /home/app
        ./cloudAPI_fake "$@"
else
    if [[ $(get_config PROXYCHAINSNG) == "yes" ]] ; then
        $YI_HACK_V5_PREFIX/bin/proxychains4 ./home/app/cloudAPI_real "$@"
    else
        cd /home/app
        ./cloudAPI_real "$@"
    fi
fi
